<template>
    <div>
        <h1>登录</h1>
        <table class="table table-bordered">
            <tr>
                <td>手机号</td>
                <td>
                    <input type="text" v-model="use.phone">
                </td>
            </tr>

            <tr>
                <td>密码</td>
                <td>
                    <input type="password" v-model="use.pwd">
                </td>
            </tr>

            <tr>
                <td></td>
                <td>
                    <input type="button" value="登录" @click="Login">
                </td>
            </tr>




        </table>
    </div>
</template>

<script setup lang="ts">
import { reactive, toRefs,onMounted } from 'vue';
import {useRouter, useRoute} from 'vue-router';
import axios from 'axios';
import { useUserStore } from '@/stores/user';
let router = useRouter();
let route = useRoute();
let userStore = useUserStore();
let data: any = reactive({
    use: {
        "phone": "123",
        "pwd": "123",
    },
});
let { use } = toRefs(data);

const Login = () => {
    let obj = {
        phone: use.value.phone,
        pwd: use.value.pwd
    }
    axios({
        url:'/api/UserInfor/GetUser',
        method: 'get',
        params: obj
    }).then((res) => {
        console.log(res);
        if (res.data.data == -1) {
            alert("手机号错误")
            return;
        } 
        else if (res.data.data == -2) {
            alert("密码错误")
            return;
        }
        else {
            alert("登录成功");
            userStore.UserInfor = res.data.data;
            router.push('/list')
        }
    })

}
</script>

<style scoped></style>